﻿using System;
using System.Collections;
using System.Web;
using System.Web.SessionState;
using ChapterX.Common;
using ChapterX.Data;

namespace ChapterX.BusinessFacade
{

    public class CurrentUserInfo
    {
        public static String Username
        {
            get
            {
                return HttpContext.Current.User.Identity.Name;
            }
        }

        public static UsersDS.UsersRow User
        {
            get
            {
                String key = "User";
                HttpSessionState session = HttpContext.Current.Session;
                if (null == session[key])
                {
                    session[key] = (new UserSystem()).GetUserByUsername(Username);
                }
                return (UsersDS.UsersRow)(session[key]);
            }
        }

        public static String Roles
        {
            get
            {
                String key = "Roles";
                HttpSessionState session = HttpContext.Current.Session;
                if (null == session[key])
                {
                    session[key] = (new UserSystem()).GetUserRoles(Username);
                }
                return (String)(session[key]);
            }
        }

        public static bool IsLibrarian
        {
            get
            {
                return Roles.Contains(UserSystem.ROLE_LIBRARIAN);
            }
        }

        public static bool IsTeacher
        {
            get
            {
                return Roles.Contains(UserSystem.ROLE_TEACHER);
            }
        }

        public static bool IsStudent
        {
            get
            {
                return Roles.Contains(UserSystem.ROLE_STUDENT);
            }
        }
    }
}
